import React, {Component} from 'react'
import { Tabs, Form } from 'antd';
import Control from './Control';
import Other from './Other';
import Package from './Package';
import Parts from './Parts';
import Receiver from './Receiver';
import StatusRule from './Other';
import MainForm from './MainForm'
//import Actions from '../ActionStore/Actions';
//import store from '../ActionStore/Stores';
const WrappedMainForm = Form.create()(MainForm);
const TabPane = Tabs.TabPane;

export default class ListInfo extends React.Component {
    constructor(props) {
        super(props);
        let searchCondition = {productCode: this.props.rowObj.productCode}
        this.state = {
            //isAdded: false,
            searchCondition: searchCondition
        };

        /*this.unsubscribe = Actions.createClick.listen( (type, rowObj) => {
            //alert("type: " + type + "rowObj: " + JSON.stringify(rowObj));
            //alert("store.listen createClick  data===="+JSON.stringify(rowObj));
            alert("xxxxxx: " + JSON.stringify(rowObj.productCode));


            let searchCondition = {productCode: rowObj.productCode}

            this.state = {
                isAdded: true,
                searchCondition: searchCondition
            };
        });*/
    }
    componentWillReceiveProps(nextProps) {
        let searchCondition = {productCode: nextProps.rowObj.productCode}
        //if(!this.state.isAdded){
            this.setState({
                searchCondition: searchCondition
            });
        //}
    }

    render() {
        //alert('this.props.isAdd: ' + JSON.stringify(this.props.isAdd));
        let tabPaneStr2;
        let tabPaneStr3;
        let tabPaneStr4;
        let tabPaneStr5;
        let tabPaneStr6;
        let tabPaneStr7;
        if(this.props.isAdd){
            tabPaneStr2 = <TabPane tab="控制信息" key="2" disabled><Control url = '/base/productcontrol/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr3 = <TabPane tab="其他信息" key="3" disabled><Other url = '/base/productother/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr4 = <TabPane tab="收货人有效管理" key="4" disabled><Receiver url = '/base/productreceiver/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr5 = <TabPane tab="产品状态规则" key="5" disabled><StatusRule url = '/base/productstatusrule/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr6 = <TabPane tab="产品多包装" key="6" disabled><Package url = '/base/productpackage/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr7 = <TabPane tab="配件" key="7" disabled><Parts url = '/base/productparts/list' searchCondition={this.state.searchCondition}/></TabPane>;
        }else{
            tabPaneStr2 = <TabPane tab="控制信息" key="2"><Control url = '/base/productcontrol/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr3 = <TabPane tab="其他信息" key="3"><Other url = '/base/productother/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr4 = <TabPane tab="收货人有效管理" key="4"><Receiver url = '/base/productreceiver/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr5 = <TabPane tab="产品状态规则" key="5"><StatusRule url = '/base/productstatusrule/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr6 = <TabPane tab="产品多包装" key="6"><Package url = '/base/productpackage/list' searchCondition={this.state.searchCondition}/></TabPane>;
            tabPaneStr7 = <TabPane tab="配件" key="7"><Parts url = '/base/productparts/list' searchCondition={this.state.searchCondition}/></TabPane>;
        }



        return (
            <Tabs tabPosition="left" defaultActiveKey="1">
                <TabPane tab="主信息" key="1"><WrappedMainForm refreshHandle = {this.refreshHandle} searchCondition={this.state.searchCondition} rowObject={this.props.rowObj} isAdd={this.props.isAdd}/></TabPane>
                {tabPaneStr2}
                {tabPaneStr3}
                {tabPaneStr4}
                {tabPaneStr5}
                {tabPaneStr6}
                {tabPaneStr7}
            </Tabs>
        );
    }
}
